package springboot.demo.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.zaxxer.hikari.HikariDataSource;
import springboot.demo.annotation.NotProfile;

@Configuration
@NotProfile("simple")
public class DataSourceConfig {

    @Value("${spring.mysql.ip}")
    String ip;

    @Value("${spring.mysql.port}")
    String port;

    @Value("${spring.mysql.password}")
    String password;

    @Bean
    public DataSource set() {
        String ipPort = ip + ":" + port;

        HikariDataSource hikariDataSource = new HikariDataSource();
        hikariDataSource.setDriverClassName("com.mysql.jdbc.Driver");
        hikariDataSource.setJdbcUrl("jdbc:mysql://" + ipPort + "/library?charactorEncoding=utf-8&useUnicode=true&useSSL=false");
        hikariDataSource.setUsername("root");
        hikariDataSource.setPassword(password);
        hikariDataSource.setMinimumIdle(10);
        hikariDataSource.setMaximumPoolSize(20);
        hikariDataSource.setConnectionTimeout(30000);
        hikariDataSource.setConnectionInitSql("select 1");
        hikariDataSource.setConnectionTestQuery("select 1");
        return hikariDataSource;
    }
}
